Setters should not return a boolean
authorChristian Persch <chpe@gnome.org>
Mon, 5 Sep 2011 20:45:44 +0000 (22:45 +0200)
committerChristian Persch <chpe@gnome.org>
Tue, 13 Sep 2011 10:55:22 +0000 (12:55 +0200)
The setter for the "font" property returned a boolean that indicated
whether the given font has been found. Instead, fall back to the default
font name when the given font doesn't exist.

gtk/gtkfontbutton.c
gtk/gtkfontchooser.c
gtk/gtkfontchooser.h
gtk/gtkfontchooserprivate.h
gtk/gtkfontchooserutils.c
gtk/gtkfontchooserwidget.c

index 7492a9a5dea8de30d6dee1b308d17ff4598fa236..dc0fde66b7fd37650fcbaa4d3bcd1359de6cb675 100644 (file)
@@ -201,13 +201,13 @@ gtk_font_button_font_chooser_get_font (GtkFontChooser *chooser)
   return g_strdup (gtk_font_button_get_font_name (font_button));
 }
 
-static gboolean
+static void
 gtk_font_button_font_chooser_set_font (GtkFontChooser *chooser,
                                        const gchar    *fontname)
 {
   GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
 
-  return gtk_font_button_set_font_name (font_button, fontname);
+  gtk_font_button_set_font_name (font_button, fontname);
 }
 
 static PangoFontFamily *
@@ -873,7 +873,6 @@ gboolean
 gtk_font_button_set_font_name (GtkFontButton *font_button,
                                const gchar    *fontname)
 {
-  gboolean result;
   gchar *old_fontname;
 
   g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE);
@@ -889,15 +888,13 @@ gtk_font_button_set_font_name (GtkFontButton *font_button,
   gtk_font_button_update_font_info (font_button);
   
   if (font_button->priv->font_dialog)
-    result = gtk_font_chooser_set_font (GTK_FONT_CHOOSER (font_button->priv->font_dialog),
-                                        font_button->priv->fontname);
-  else
-    result = FALSE;
+    gtk_font_chooser_set_font (GTK_FONT_CHOOSER (font_button->priv->font_dialog),
+                               font_button->priv->fontname);
 
   g_object_notify (G_OBJECT (font_button), "font");
   g_object_notify (G_OBJECT (font_button), "font-name");
 
-  return result;
+  return TRUE;
 }
 
 static void
index cdc8d5acbc0be315f1bd7024c90f41ba7899f8ba..c83174f4caee4af37a81688862c38b9120edca61 100644 (file)
@@ -50,9 +50,6 @@ enum
 
 static guint chooser_signals[LAST_SIGNAL];
 
-#define DEFAULT_FONT_NAME "Sans 10"
-#define MAX_FONT_SIZE 999
-
 typedef GtkFontChooserIface GtkFontChooserInterface;
 G_DEFINE_INTERFACE (GtkFontChooser, gtk_font_chooser, G_TYPE_OBJECT);
 
@@ -64,7 +61,7 @@ gtk_font_chooser_default_init (GtkFontChooserInterface *iface)
       g_param_spec_string ("font",
                           P_("Font"),
                           P_("The string that represents this font"),
-                          DEFAULT_FONT_NAME,
+                          GTK_FONT_CHOOSER_DEFAULT_FONT_NAME,
                           GTK_PARAM_READWRITE));
 
   g_object_interface_install_property
@@ -201,21 +198,17 @@ gtk_font_chooser_get_font (GtkFontChooser *fontchooser)
  *
  * Sets the currently-selected font.
  *
- * Return value: %TRUE if the font could be set successfully; %FALSE
- *     if no such font exists or if the @fontchooser doesn't belong
- *     to a particular screen yet.
- *
  * Since: 3.2
  */
-gboolean
+void
 gtk_font_chooser_set_font (GtkFontChooser *fontchooser,
                            const gchar    *fontname)
 {
-  g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), FALSE);
-  g_return_val_if_fail (fontname != NULL, FALSE);
+  g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser));
+  g_return_if_fail (fontname != NULL);
 
-  return GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->set_font (fontchooser,
-                                                             fontname);
+  GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->set_font (fontchooser,
+                                                      fontname);
 }
 
 /**
index 39c503ce48811b7a9952033f4de6d0115aeb2200..8573f8ccf220f6401fd643e75a0d3bb8b013eccc 100644 (file)
@@ -60,7 +60,7 @@ struct _GtkFontChooserIface
 
   /* Methods */
   gchar *           (* get_font)                (GtkFontChooser *chooser);
-  gboolean          (* set_font)                (GtkFontChooser *chooser,
+  void              (* set_font)                (GtkFontChooser *chooser,
                                                  const gchar    *fontname);
   PangoFontFamily * (* get_font_family)         (GtkFontChooser  *chooser);
   PangoFontFace *   (* get_font_face)           (GtkFontChooser  *chooser);
@@ -85,7 +85,7 @@ PangoFontFace   *gtk_font_chooser_get_face                 (GtkFontChooser   *fo
 gint             gtk_font_chooser_get_size                 (GtkFontChooser   *fontchooser);
 gchar*           gtk_font_chooser_get_font                 (GtkFontChooser   *fontchooser);
 
-gboolean         gtk_font_chooser_set_font                 (GtkFontChooser   *fontchooser,
+void             gtk_font_chooser_set_font                 (GtkFontChooser   *fontchooser,
                                                             const gchar      *font_name);
 gchar*           gtk_font_chooser_get_preview_text         (GtkFontChooser   *fontchooser);
 void             gtk_font_chooser_set_preview_text         (GtkFontChooser   *fontchooser,
index 8a8ac3514c9ca52920300fb92d5840c81aa1949e..ef6255357ab1233c7bd3354561e48daada8ccdb6 100644 (file)
@@ -25,6 +25,8 @@
 
 #include "gtkfontchooser.h"
 
+#define GTK_FONT_CHOOSER_DEFAULT_FONT_NAME "Sans 10"
+
 G_BEGIN_DECLS
 
 void            _gtk_font_chooser_font_activated        (GtkFontChooser *chooser,
index 5cef3a0747e25ec8a9230119bbf1a23795bdd32b..418442f2b6c4f71e14617f329f9085f23d0b954e 100644 (file)
@@ -41,11 +41,11 @@ delegate_get_font (GtkFontChooser *chooser)
   return gtk_font_chooser_get_font (get_delegate (chooser));
 }
 
-static gboolean
+static void
 delegate_set_font (GtkFontChooser *chooser,
                         const gchar    *fontname)
 {
-  return gtk_font_chooser_set_font (get_delegate (chooser), fontname);
+  gtk_font_chooser_set_font (get_delegate (chooser), fontname);
 }
 
 static PangoFontFamily *
index cc6306ea6a0b49406d2d1ddf1e0dda3ab9789bf3..568df2fc0f3f999642035acb038e7e01194dfea2 100644 (file)
@@ -146,10 +146,10 @@ static void gtk_font_chooser_widget_style_updated        (GtkWidget       *widge
 
 static void gtk_font_chooser_widget_bootstrap_fontlist   (GtkFontChooserWidget *fontchooser);
 
-static gboolean gtk_font_chooser_widget_select_font_name (GtkFontChooserWidget *fontchooser);
+static void gtk_font_chooser_widget_select_font_name     (GtkFontChooserWidget *fontchooser);
 
 static gchar   *gtk_font_chooser_widget_get_font         (GtkFontChooser *chooser);
-static gboolean gtk_font_chooser_widget_set_font         (GtkFontChooser *chooser,
+static void     gtk_font_chooser_widget_set_font         (GtkFontChooser *chooser,
                                                           const gchar     *fontname);
 
 static const gchar *gtk_font_chooser_widget_get_preview_text (GtkFontChooserWidget *fontchooser);
@@ -945,8 +945,7 @@ gtk_font_chooser_widget_screen_changed (GtkWidget *widget,
                  GTK_TREE_VIEW (priv->family_face_list),
                  priv->model);
 
-  if (priv->fontname)
-    gtk_font_chooser_widget_select_font_name (fontchooser);
+  gtk_font_chooser_widget_select_font_name (fontchooser);
 }
 
 static void
@@ -994,7 +993,7 @@ gtk_font_chooser_widget_get_font (GtkFontChooser *chooser)
   PangoFontDescription *desc;
 
   if (!fontchooser->priv->face)
-    return NULL;
+    return g_strdup (GTK_FONT_CHOOSER_DEFAULT_FONT_NAME);
 
   desc = pango_font_face_describe (fontchooser->priv->face);
   font_desc_name = pango_font_description_to_string (desc);
@@ -1006,27 +1005,24 @@ gtk_font_chooser_widget_get_font (GtkFontChooser *chooser)
   return font_name;
 }
 
-static gboolean
+static void
 gtk_font_chooser_widget_set_font (GtkFontChooser *chooser,
                                   const gchar    *fontname)
 {
   GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (chooser);
   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
-  gboolean found = FALSE;
 
   if (priv->fontname)
     g_free (priv->fontname);
   priv->fontname = g_strdup (fontname);
 
   if (gtk_widget_has_screen (GTK_WIDGET (fontchooser)))
-    found = gtk_font_chooser_widget_select_font_name (fontchooser);
+    gtk_font_chooser_widget_select_font_name (fontchooser);
 
   g_object_notify (G_OBJECT (fontchooser), "font");
-
-  return found;
 }
 
-static gboolean
+static void
 gtk_font_chooser_widget_select_font_name (GtkFontChooserWidget *fontchooser)
 {
   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
@@ -1036,7 +1032,11 @@ gtk_font_chooser_widget_select_font_name (GtkFontChooserWidget *fontchooser)
   PangoFontDescription *desc;
   gboolean found = FALSE;
 
-  desc = pango_font_description_from_string (priv->fontname);
+  if (priv->fontname)
+    desc = pango_font_description_from_string (priv->fontname);
+  else
+    desc = pango_font_description_from_string (GTK_FONT_CHOOSER_DEFAULT_FONT_NAME);
+
   family_name = (gchar*)pango_font_description_get_family (desc);
 
   g_free (priv->fontname);
@@ -1045,7 +1045,7 @@ gtk_font_chooser_widget_select_font_name (GtkFontChooserWidget *fontchooser)
   if (!family_name)
     {
       pango_font_description_free (desc);
-      return FALSE;
+      return;
     }
 
   /* We make sure the filter is clear */
@@ -1112,8 +1112,6 @@ gtk_font_chooser_widget_select_font_name (GtkFontChooserWidget *fontchooser)
     }
 
   pango_font_description_free (desc);
-
-  return found;
 }
 
 static const gchar*